$(document).ready(function(){
	var $container = $('#container');

function callIsotope(){
$container.isotope({
        masonry: {
          columnWidth: 10
        },
        sortBy: 'number',
        getSortData: {
          alphabetical: function( $elem ) {
            var name = $elem.find('.name'),
                itemText = name.length ? name : $elem;
            return itemText.text();
          }
        },
        transformsEnabled: false
      });
}

$(window).load( function(){ callIsotope(); });
  
      
      var $optionSets = $('#options .option-set'),
          $optionLinks = $optionSets.find('a');

      $optionLinks.click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
          return false;
        }
        var $optionSet = $this.parents('.option-set');
        $optionSet.find('.selected').removeClass('selected');
        $this.addClass('selected');
  
        // make option object dynamically, i.e. { filter: '.my-filter-class' }
        var options = {},
            key = $optionSet.attr('data-option-key'),
            value = $this.attr('data-option-value');
        // parse 'false' as false boolean
        value = value === 'false' ? false : value;
        options[ key ] = value;
        if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
          // changes in layout modes need extra logic
          changeLayoutMode( $this, options )
        } else {
          // otherwise, apply new options
          $container.isotope( options );
        }
        
        return false;
      });
$(".toggleHoverText").click(function( e ) {
      e.stopPropagation();
      $('.element').css('z-index','100');
      $(this).parent().parent().css({zIndex:101});
      var $this = $( this ), elements = $this.parent().find( '.hoverText:visible' );
      if( elements.length > 0 ) {
        elements.fadeOut( 'fast', function() { callIsotope()  });
      } else {
        $( '#' + $this.attr( 'rel' ) ).fadeToggle( 'fast' , function(){ callIsotope()  });
      }
      
    });


  $( '.hoverText' ).click(function(e){
       e.stopPropagation();
       $(this).show(function(){ callIsotope() });
     
   });
	 /*$(".toggleHoverText").click(function( e ) {
			e.stopPropagation();
			$('.element').css('z-index','100');
			$(this).parent().parent().css({zIndex:101});
			var $this = $( this ), elements = $( '.hoverText:visible' );
			if( elements.length > 0 ) {
				elements.fadeOut( 'fast', function() {
					if( elements.attr('id') != $this.attr( 'rel' ) ){
						$( '#' + $this.attr( 'rel' ) ).fadeToggle( 'fast' , function(){ callIsotope()  });
					}
          callIsotope();
				});
			} else {
				$( '#' + $this.attr( 'rel' ) ).fadeToggle( 'fast' , function(){ callIsotope()  });
			}
      
		});
	 
   
	 $( document ).bind( 'click', function() {
		$( ".toggleHoverText" ).each( function() {
			var element = $(this).parent().parent().find('.hoverText');
			if( !element.is( ':hidden' ) ) {
				element.fadeToggle(function(){
          callIsotope();
        });

			}
		});
	});*/
				
  });